/*
 * @Description: 表单混入
 * @Version: 0.0.1
 * @Autor: zhj1214
 * @Date: 2021-06-04 09:57:21
 * @LastEditors: zhj1214
 * @LastEditTime: 2021-06-07 15:11:49
 */
import _ from "lodash";
export default {
  data: function() {
    return {
      componentData: {},
      attrsCopy: {}
    };
  },
  created() {
    this.$ebs.$on(this.type, param => {
      let reluts = param;
      delete reluts.componentsProps;

      Object.keys(reluts.data).forEach(key => {
        if (!this[key]) {
          this.$set(this.componentData, key, reluts.data[key]);
        }
      });
    });
  },
  watch: {
    $attrs: {
      handler(newVal, value) {
        if (!_.isEqual(newVal, value)) {
          if (_.isEqual(newVal, {})) {
            this.attrsCopy = _.cloneDeep(value);
          } else {
            this.one_t = true;
            this.attrsCopy = _.cloneDeep(newVal);
          }
        }
      },
      immediate: true
    },
    "componentData.model": function(newVal, oldVal) {
      if (newVal != oldVal) {
        let reluts = {};
        reluts[`${this.type}Model`] = newVal;
        // console.log(this.type, "~~~~~", newVal);
        this.$emit("modelWatch", reluts);
      }
    }
  }
};
